package cn.wps.moffice.common.document_fix.ext.net; import android.content.Context; import android.text.TextUtils; import cn.wps.moffice.OfficeApp; import cn.wps.moffice_eng.R; import com.baidu.tts.loopj.AsyncHttpResponseHandler; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import defpackage.dhh; import java.io.File; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; public class DocFixNetManagerImpl implements dhh { private static final String FIX_FILE_CHECK_URL = "https://doc-repair.wps.cn/docrcs/getinfo.php?d="; private static final String FIX_FILE_DOWNLOAD_URL = "https://doc-repair.wps.cn/o/"; private static final String FIX_FILE_UPLOAD_URL = "https://doc-repair.wps.cn/docrcs/doupload.php?d="; private static final String FIX_IMG_DOWNLOAD_URL = "https://doc-repair.wps.cn/docrcs/getpic.php?d="; private static final String TAG = "DocFixNetManagerImpl"; private final String ENCRYPT_KEY = "548f0e53"; private final String SIGN_KEY = "123"; private boolean isCancelDownload; private boolean isCancelUpload; private Context mContext; private Gson mGson; public DocFixNetManagerImpl(Context context) { this.mContext = context; this.mGson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); } private boolean deleteFile(String str) { if (hx.f(str)) { return true; } File file = new File(str); if (!file.exists()) { return true; } if (file.isFile()) { return file.delete(); } if (!file.isDirectory()) { return false; } File[] listFiles = file.listFiles(); for (File file2 : listFiles) { if (file2.isFile()) { file2.delete(); } else if (file2.isDirectory()) { deleteFile(file2.getAbsolutePath()); } } return file.delete(); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void eventFileUploadFailureHappened(String str) { HashMap hashMap = new HashMap(); hashMap.put("errcode", "0"); hashMap.put("info", str); dwp.l("public_filerepair_upload_error", hashMap); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private File genFile(String str) { String IS = lwv.IS(new File(str).getName()); String str2 = OfficeApp.arx().arM().lZb + this.mContext.getString(R.string.apps_introduce_doucument_fix_title) + "/"; File file = new File(str2); if (!file.exists()) { file.mkdirs(); } String str3 = IS + "(%d)"; File file2 = new File(str2, IS); int i = 1; while (file2.exists()) { i++; file2 = new File(str2, String.format(str3, Integer.valueOf(i))); } return file2; } public boolean checkFileList(ArrayList<String> arrayList, String str) { if (arrayList == null || arrayList.isEmpty()) { return false; } String saveFilePath = getSaveFilePath(str); Iterator<String> it = arrayList.iterator(); while (it.hasNext()) { if (!new File(saveFilePath + it.next().replace("\\", "/")).exists()) { deleteFile(saveFilePath); return false; } } return true; } @Override // defpackage.dhh public void checkFixFile(final String str, final String str2, final dhh.b bVar) { fcx.p(new Runnable() { /* class cn.wps.moffice.common.document_fix.ext.net.DocFixNetManagerImpl.AnonymousClass2 */ public final void run() { try { if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) { dhm dhm = (dhm) DocFixNetManagerImpl.this.mGson.fromJson(lwd.z(lwd.d(DocFixNetManagerImpl.FIX_FILE_CHECK_URL + URLEncoder.encode(dgw.af(String.valueOf(System.currentTimeMillis() / 1000) + "|123" + "|" + str2 + "|" + fok.bBq().bBy() + "|" + str, "548f0e53"), AsyncHttpResponseHandler.DEFAULT_CHARSET), null, null)), dhm.class); if (dhm != null && dhm.errorCode == 0 && !TextUtils.isEmpty(dhm.info)) { String ag = dgw.ag(dhm.info, "548f0e53"); dhm jy = "2".equals(str2) ? (dhm) DocFixNetManagerImpl.this.mGson.fromJson(ag, dhk.class) : dha.jy(ag); if (bVar != null) { bVar.a(jy); } } else if (bVar != null) { bVar.b(dhm); } } } catch (Exception e) { if (bVar != null) { bVar.b(null); } } } }); } public String convertImgUrl(String str, String str2) { if (!TextUtils.isEmpty(str2)) { try { return FIX_IMG_DOWNLOAD_URL + URLEncoder.encode(dgw.af(String.valueOf(System.currentTimeMillis() / 1000) + "|" + "123" + "|" + fok.bBq().bBy() + "|" + str + "|" + str2, "548f0e53"), AsyncHttpResponseHandler.DEFAULT_CHARSET); } catch (Exception e) { e.getMessage(); } } return null; } public void downloadZipFile(final String str, final String str2, final dhh.a aVar) { fcx.p(new Runnable() { /* class cn.wps.moffice.common.document_fix.ext.net.DocFixNetManagerImpl.AnonymousClass3 */ public final void run() { try { DocFixNetManagerImpl.this.setCancelDownload(false); String bBy = fok.bBq().bBy(); dhd dhd = new dhd(); dhd.url = DocFixNetManagerImpl.FIX_FILE_DOWNLOAD_URL + bBy + "/" + str + ".zip"; new StringBuilder(DocFixNetManagerImpl.FIX_FILE_DOWNLOAD_URL).append(bBy).append("/").append(str).append(".zip"); dhd.dyQ = new HashMap<>(); dhb dhb = new dhb(); dhb.dyN = new dhh.d() { /* class cn.wps.moffice.common.document_fix.ext.net.DocFixNetManagerImpl.AnonymousClass3.AnonymousClass1 */ @Override // defpackage.dhh.d public final boolean isCanceled() { return DocFixNetManagerImpl.this.isCancelDownload; } }; dhb.dyO = aVar; dhb.a(dhd, DocFixNetManagerImpl.this.genFile(str2)); } catch (Exception e) { if (aVar != null) { aVar.onError(); } } } }); } @Override // defpackage.dhh public void fixFileUploader(final String str, final dhh.c cVar) { fcx.p(new Runnable() { /* class cn.wps.moffice.common.document_fix.ext.net.DocFixNetManagerImpl.AnonymousClass1 */ public final void run() { File file = new File(str); try { dhc dhc = new dhc(); dhc.dyN = new dhh.d() { /* class cn.wps.moffice.common.document_fix.ext.net.DocFixNetManagerImpl.AnonymousClass1.AnonymousClass1 */ @Override // defpackage.dhh.d public final boolean isCanceled() { return DocFixNetManagerImpl.this.isCancelUpload; } }; dhc.dyP = cVar; dhd dhd = new dhd(); dhd.url = DocFixNetManagerImpl.FIX_FILE_UPLOAD_URL + URLEncoder.encode(dgw.af(String.valueOf(System.currentTimeMillis() / 1000) + "|123" + "|" + fok.bBq().bBy(), "548f0e53"), AsyncHttpResponseHandler.DEFAULT_CHARSET); dhd.dyQ = new HashMap<>(); dhm dhm = (dhm) DocFixNetManagerImpl.this.mGson.fromJson(dhc.b(dhd, file), dhm.class); if (dhm != null && dhm.errorCode == 0) { String ag = dgw.ag(dhm.info, "548f0e53"); if (!TextUtils.isEmpty(ag) && ag.indexOf("|") != -1) { int indexOf = ag.indexOf("|"); ag.substring(0, indexOf); String substring = ag.substring(indexOf + 1); int indexOf2 = substring.indexOf("|"); String substring2 = substring.substring(0, indexOf2); String substring3 = substring.substring(indexOf2 + 1); DocFixNetManagerImpl.this.eventFileUploadFailureHappened(substring3); if (cVar != null) { cVar.onSuccess(substring3, substring2); } } else if (cVar != null) { cVar.b(null); } } else if (cVar != null) { cVar.b(dhm); } } catch (Exception e) { if (cVar != null) { cVar.b(null); } } } }); } public String getSaveFilePath(String str) { return OfficeApp.arx().arM().lZb + this.mContext.getString(R.string.apps_introduce_doucument_fix_title) + "/" + lwv.IS(str) + "/"; } @Override // defpackage.dhh public void setCancelDownload(boolean z) { this.isCancelDownload = z; } public void setCancelUpload(boolean z) { this.isCancelUpload = z; } }